#include <limits.h>
#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

/**
 * Definition for singly-linked list.
 */
struct ListNode {
	int val;
	struct ListNode* next;
};
typedef struct ListNode listNode, *list_node;

struct ListNode* detectCycle(struct ListNode* head);

int main()
{
	return 0;
}

struct ListNode* detectCycle(struct ListNode* head)
{
	list_node slow = head, fast = head;
	while (fast) {
		if (fast->next) fast = fast->next;
		else 			return NULL;
		slow = slow->next;
		fast = fast->next;
		if (fast == slow) break;
	}
	if (!fast) return NULL;

	while (head != slow) {
		head = head->next;
		slow = slow->next;
	}

	return head;
}
